home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows1 / boss_sup.zip / PDDEMO.C < prev    next >
C/C++ Source or Header  |  1992-03-05  |  28KB  |  780 lines

  1. /*
  2. ** DEMONSTRATION OF PULLDOWN MENU SYSTEM USING WINDOWS BOSS.
  3. **
  4. ** Adapted, with permission, from Keith Funk's code.
  5. **
  6. ** Copyright (C) 1992 - Philip A. Mongelluzzo
  7. ** All Rights Reserved.
  8. **
  9. ** Contains all the code needed to implement a complete menuing system
  10. ** including active/inactive menus and menu options, toggle style options,
  11. ** multi-level pulldowns, and more.
  12. */
  13.  
  14. /*
  15. ** Keep everyone happy!!
  16. */
  17.  
  18. int  DoMenu(void);
  19. void domodem(int ch);
  20. void dosetup(int ch);
  21. void dofileman(int ch);
  22. void doview(int ch);
  23. void dographics(int Choice);
  24. void dorun(void);
  25. void doedit(int ch);
  26. void dohelp(int ch);
  27.  
  28. #include "winboss.h"
  29.  
  30. int wa, ba, hka;
  31.  
  32. WNPD mainbar = {
  33.   WNLPTR, 0, 0, 0, FALSE, 0,            /* Standard Preamble */
  34.   0, 6, {                               /* first & last selectable option */
  35.   0, 0,  " File ", 'F', 1, 'A', 1,      /* F = the hotkey for this option */
  36.   0, 6,  " Edit ", 'E', 1, 'A', 2,      /* 1 = option is active. */
  37.   0, 12, " View ", 'V', 1, 'A', 3,      /* A = an action type option. */
  38.   0, 18, " Run ",  'R', 0, 'N', 4,      /* N = no pulldown for this option */
  39.   0, 23, " Setup ",'S', 1, 'A', 5,      /* N is only used in main menus */
  40.   0, 30, " Modem ",'M', 1, 'A', 6,      /* 6 = the return code. */
  41.   0, 50, " Help ", 'H', 1, 'A', 7,      /* Note that the Run option is */
  42.   99,99, "",99 }                        /* inactive. Selecting File/Load */
  43. };                                      /* will activate it. */
  44.  
  45. WNPD pdfile = {
  46.   WNLPTR, 0, 0, 0, FALSE, 0,            /* Standard Preamble */
  47.   0, 9, {
  48.   0, 0, " Load      ", 'L', 1, 'A', 1,
  49.   1, 0, " Save      ", 'S', 1, 'A', 2,
  50.   2, 0, " Save As   ", 'A', 1, 'A', 3,
  51.   3, 0, "───────────", ' ', 0, 'A', 0,  /* '─' is char ALT-196 */
  52.   4, 0, " Chdir     ", 'C', 1, 'A', 4,
  53.   5, 0, "───────────", ' ', 0, 'A', 0,  /* not an option, Must be inactive. */
  54.   6, 0, " Print     ", 'P', 0, 'A', 5,
  55.   7, 0, "───────────", ' ', 0, 'A', 0,
  56.   8, 0, " DOS Shell ", 'D', 0, 'A', 6,  /* 0 = inactive menu option */
  57.   9, 0, " Exit      ", 'x', 1, 'A', 7,  /* hotkeys are case sensitive */
  58.   99, 99, "",99 }
  59. };
  60.  
  61. WNPD pdedit = {
  62.   WNLPTR, 0, 0, 0, FALSE, 0,            /* Standard Preamble */
  63.   0, 2, {
  64.   0, 0, " Cut   ", 't', 1, 'A', 1,      /* Paste is inactive. */
  65.   1, 0, " Copy  ", 'C', 1, 'A', 2,      /* NEVER de-activate a main menu */
  66.   2, 0, " Paste ", 'P', 0, 'A', 3,      /* option that has a pulldown. */
  67.   99, 99, "",99 }                       /* De-activate the pulldown instead*/
  68. };                                      /* so user can see, but not select */
  69.  
  70. WNPD pdview = {
  71.   WNLPTR, 0, 0, 0, FALSE, 0,            /* Standard Preamble */
  72.   0, 2, {
  73.   0, 0, " Input    ", 'I', 0, 'A', 1,   /* all initially inactive, but */
  74.   1, 0, " Output   ", 'O', 0, 'A', 2,   /* will be activated by user */
  75.   2, 0, " Graphics ", 'G', 0, 'A', 3,   /* selecting File/Load and Run */
  76.   99, 99, "",99 }                       /* menu options. */
  77. };
  78.  
  79. WNPD pdsetup = {
  80.   WNLPTR, 0, 0, 0, FALSE, 0,            /* Standard Preamble */
  81.   0, 2, {
  82.   0, 0, " Color    ", 'C', 1, 'T', 1,   /* T = a non-exclusive toggle. */
  83.   1, 0, " Printer  ", 'P', 1, 'A', 2,
  84.   2, 0, " Plotter  ", 'l', 1, 'A', 3,
  85.   99, 99, "",99 }
  86. };
  87.  
  88. WNPD pdmodem = {
  89.   WNLPTR, 0, 0, 0, FALSE, 0,            /* Standard Preamble */
  90.   0, 1, {
  91.   0, 0, " Receive    ", 'R', 1, 'A', 1,
  92.   1, 0, " Send       ", 'S', 1, 'A', 2,
  93.   2, 0, "────────────", ' ', 0, 'A', 0, /* comments must be specified */
  94.   3, 0, " MODEM MUST ", ' ', 0, 'A', 0, /* as inactive. */
  95.   4, 0, "   BE ON    ", ' ', 0, 'A', 0,
  96.   99, 99, "",99 }
  97. };
  98.  
  99. WNPD pdhelp = {
  100.   WNLPTR, 0, 0, 0, FALSE, 0,            /* Standard Preamble */
  101.   0, 3, {
  102.   0, 0, " Contents     ", 'C', 1, 'A', 1,
  103.   1, 0, " Index        ", 'I', 1, 'A', 2,
  104.   2, 0, " Topic     F1 ", 'T', 1, 'A', 3,
  105.   3, 0, " Help On Help ", 'H', 1, 'A', 4,
  106.   99, 99, "",99 }
  107. };
  108.  
  109. WNPD pdprinters = {
  110.   WNLPTR, 0, 0, 0, FALSE, 0,            /* Standard Preamble */
  111.   0, 4, {
  112.   0, 0, " Amdex  ", 'A', 1, 'E', 1,     /* E = mutually Exclusive toggles */
  113.   1, 0, " Epson  ", 'E', 1, 'E', 2,     /* only one can be ON at a time. */
  114.   2, 0, " HP     ", 'H', 1, 'E', 3,
  115.   3, 0, " Roland ", 'R', 1, 'E', 4,
  116.   4, 0, " QMS    ", 'Q', 1, 'E', 5,
  117.   5, 0, "────────", ' ', 0, 'A', 0,
  118.   6, 0, " ESC TO ", ' ', 0, 'A', 0,
  119.   7, 0, "  EXIT  ", ' ', 0, 'A', 0,
  120.   99, 99, "",99}
  121. };
  122.  
  123. WNPD pdgraph = {
  124.   WNLPTR, 0, 0, 0, FALSE, 0,            /* Standard Preamble */
  125.   0, 3, {
  126.   0, 0, " X Axis     ", 'X', 1, 'A', 1,
  127.   1, 0, " Y Axis     ", 'Y', 1, 'A', 2,
  128.   2, 0, " Options    ", 'O', 1, 'A', 3,
  129.   3, 0, " Draw Graph ", 'D', 0, 'A', 4, /* inactive tell X & Y selected */
  130.   99, 99, "",99 }
  131. };
  132.  
  133. WNPD pdxaxis = {
  134.   WNLPTR, 0, 0, 0, FALSE, 0,            /* Standard Preamble */
  135.   0, 4, {
  136.   0, 0, " Time         ", 'T', 1, 'E', 1,
  137.   1, 0, " Stress       ", 'S', 1, 'E', 2,   /* duplicate items in */
  138.   2, 0, " Strain       ", 'r', 1, 'E', 3,   /* this menu and the X */
  139.   3, 0, " Axial Load   ", 'A', 1, 'E', 4,   /* axis menu MUST have */
  140.   4, 0, " Lateral Load ", 'L', 1, 'E', 5,   /* the same return code. */
  141.   99, 99, "",99}
  142. };
  143.  
  144. WNPD pdyaxis = {
  145.   WNLPTR, 0, 0, 0, FALSE, 0,            /* Standard Preamble */
  146.   2, 7, {
  147.   0, 0, " SELECT ONE OR MORE ", ' ', 0, 'A', 0,
  148.   1, 0, "────────────────────", ' ', 0, 'A', 0,
  149.   2, 0, " Stress             ", 'S', 1, 'T', 2,
  150.   3, 0, " Strain             ", 'r', 1, 'T', 3,
  151.   4, 0, " Axial Load         ", 'A', 1, 'T', 4,
  152.   5, 0, " Lateral Load       ", 'L', 1, 'T', 5,
  153.   6, 0, " Transducer Voltage ", 'V', 1, 'T', 6,
  154.   7, 0, " Clear All Options  ", 'C', 1, 'A', 7,
  155.   99, 99, "",99}
  156. };
  157.  
  158. main()
  159. {
  160. unsigned int ch;
  161. WINDOWPTR mainwin, msgwin;
  162. int i;
  163.  
  164.   int AllDone = 0;                      /* 1 = exit program */
  165.   wn_init();                            /* save entry screen */
  166.   v_cls(NVIDEO);                        /* clear screen */
  167.   wn_border(1);                         /* single ruled border */
  168.  
  169. /*
  170. ** window for main program to execute in
  171. */
  172.  
  173.   mainwin = wn_open(0, 1, 0, 78, 21, v_setatr(BLUE,WHITE,0,BOLD), NVIDEO);
  174.  
  175. /* 
  176. ** window to display messages 
  177. */
  178.  
  179.   msgwin = wn_open(1000, 24,0,80,1, v_setrev(NVIDEO), v_setrev(NVIDEO));
  180.  
  181.   wa = v_setatr(WHITE,BLACK,0,0);       /* window attirbute. */
  182.   ba = v_setatr(WHITE,BLACK,0,0);       /* border attribute. */
  183.   hka = v_setatr(WHITE,WHITE,0,BOLD);   /* hotkey attribute. */
  184.  
  185. /*
  186. ** Menu Bar
  187. */
  188.  
  189.   wn_pdopen(1000,0,0,80,1,wa,ba,hka, &mainbar, FALSE); 
  190.  
  191. /* 
  192. ** Explain a bit about the demo program. 
  193. */
  194.  
  195.   wn_puts(mainwin, 1, 13, "              PULLDOWN MENU DEMO PROGRAM");
  196.   wn_puts(mainwin, 3, 13, "1. Run is inactive until you select File/Load.");
  197.   wn_puts(mainwin, 4, 13, "2. The View options are activated by File/Load and Run.");
  198.   wn_puts(mainwin, 5, 13, "3. Edit/Paste and File/DOS options are never activated.");
  199.   wn_puts(mainwin, 6, 13, "4. Setup/Printers activates the File/Print option.");
  200.   wn_puts(mainwin, 7, 13, "5. Selecting X and Y axis options, activates Display Graph.");
  201.   wn_puts(mainwin, 8, 13, "6. When a pulldown menu is active, use the left/right");
  202.   wn_puts(mainwin, 9, 13, "   arrow keys to view others. Run has no pulldown menu.");
  203.  
  204. /*
  205. ** Provide instructions on message line...
  206. */ 
  207.  
  208.   wn_puts(msgwin, 0, 1, "<Slash Key '/' Activates The Menu>");
  209.  
  210. /*
  211. ** main program loop. Does nothing practical. Simply displays a moving
  212. ** counter to show that the program is doing something until the
  213. ** user activates the menu. 
  214. */
  215.  
  216.   i = 0;
  217.   while (!AllDone)
  218.   {
  219.     while (!v_kstat())                  /* do stuff until key hit */
  220.     {
  221.       wn_locate(mainwin, 12, 26);
  222.       wn_printf(mainwin, "Main Program Is Running %5d", i);
  223.       i = (++i > 32000) ? 0 : i;
  224.     }
  225.  
  226.     ch = (v_getch() & 0x7F);            /* get the key pressed. */
  227.     if (ch == '/')                      /* activate the menu */
  228.     {
  229.       wn_clr(msgwin);
  230.       wn_puts(msgwin, 0, 1, "<ESC Exits Menus>  <Any Key Exits Messages>");
  231.       wn_locate(mainwin, 12, 26);
  232.       wn_printf(mainwin, "                                  ");
  233.  
  234.       AllDone = DoMenu();               /* activate the menu */
  235.       if (AllDone) break;               /* end the program */
  236.       wn_pdopen(1000,0,0,80,1,wa,ba,hka, &mainbar, FALSE); 
  237.       wn_clr(msgwin);
  238.       wn_puts(msgwin, 0, 1, "<Slash Key '/' Activates The Menu>");
  239.     }
  240.   }
  241.  
  242.   wn_pdclose(&mainbar);
  243.   wn_close(mainwin);
  244.   wn_close(msgwin);
  245.   wn_exit();
  246.   exit(0);
  247. }
  248.  
  249. /* 
  250. ** This routine activates the main menu and gets main menu choices. It
  251. ** then activates a pulldown menu and passes the pulldown menu choice
  252. ** to other routines that would do the processing. It returns 1 (TRUE)
  253. ** when the user selects the EXIT option of the FILE menu. This signals
  254. ** the main routine to exit the program. Otherwise it returns 0.
  255. **
  256. ** Pulldown menus are either 'single shot', after you make a selection, the
  257. ** menu disappears, or 'sticky', you can make multiple selections and
  258. ** must press ESC or left/right arrow to close the menu. 
  259. */
  260.  
  261. /* 
  262. ** If ForceChoice != -1, in PULL DOWN loop, user has exited a pulldown 
  263. ** menu via the left or right arrow keys. So we want to automatically move to
  264. ** the next main menu choice and immediately activate its menu 
  265. */
  266.  
  267. int DoMenu(void)
  268. {
  269. int rv;                                 /* main menu choice. */
  270. int currch;                             /* pulldown menu choice */
  271. int ForceChoice;                        /* force a bar menu selection */
  272.  
  273.   wn_border(1);                         /* single ruled border */
  274.   ForceChoice = -1;                     /* let user pick a choice */
  275.   wn_pdopen(1000,0,0,80,1,wa,ba,hka, &mainbar, TRUE);  /* activate main menu. */
  276.  
  277.   while (TRUE) {                        /* Pull down Loop */
  278.     if (ForceChoice != -1)              /* instantly activate barmenu */
  279.     {
  280.       wn_pdupdate(&mainbar, ForceChoice, PDREVERSE); /* hilite new choice. */
  281.       rv = mainbar.scrn[ForceChoice].rv;       /* activate it. */
  282.     }
  283.     else
  284.       rv = wn_pdget(&mainbar);          /* get a menu selection. */
  285.     switch (rv) {                       /* dispatch based on mainbar */
  286.       case 1:                           /* Filemanager-single shot, 7 EXITS */
  287.         if (wn_pdopen(510,1,0,11,10,wa,ba,hka,&pdfile, TRUE))
  288.         {
  289.           currch = wn_pdget(&pdfile);   /* get pulldown choice. */
  290.           if (currch < 97)              /* if user made a choice */
  291.           {
  292.             wn_pdclose(&pdfile);        /* close pulldown */
  293.             dofileman(currch);          /* execute option action. */
  294.             if(currch == 7)             /* EXIT so, terminate program */
  295.               {
  296.                 wn_pdclose(&pdfile);
  297.                 return(1);              /* indicates EXIT program */
  298.               }
  299.             return(0);                  /* exit menu system. */
  300.           }
  301.         }
  302.         break;
  303.  
  304.       case 2:                           /* Edit - single shot menu */
  305.         if (wn_pdopen(510,1,5,7,3,wa,ba,hka,&pdedit, TRUE))      /* if pulldown gets opened. */
  306.         {
  307.           currch = wn_pdget(&pdedit);   /* get pulldown choice. */
  308.           if (currch < 97)              /* if user made a choice */
  309.           {
  310.             wn_pdclose(&pdedit);        /* close pulldown */
  311.             doedit(currch);             /* execute option action. */
  312.             return(0);                  /* exit menu system. */
  313.           }
  314.         }
  315.         break;
  316.  
  317.       case 3:                           /* View - sticky menu */
  318.         if (wn_pdopen(510,1,11,10,3,wa,ba,hka,&pdview, TRUE))
  319.         {
  320.           do
  321.           {
  322.             currch = wn_pdget(&pdview); /* get pulldown choice. */
  323.             if (currch < 97)            /* if user made a choice */
  324.               doview(currch);           /* execute option action. */
  325.           }  while (currch < 97);
  326.         wn_pdclose(&pdview);            /* NOW, close pulldown */
  327.         }
  328.         break;
  329.  
  330.       case 4:                           /* Run - No pulldown menu */
  331.         dorun();                        /* execute option action. */
  332.         return(0);                      /* exit menu system. */
  333.         break;
  334.  
  335.       case 5:                           /* Setup -  STICKY menu */
  336.         if (wn_pdopen(510,1,22,10,3,wa,ba,hka,&pdsetup, TRUE))
  337.         {
  338.           do
  339.           {
  340.             currch = wn_pdget(&pdsetup);/* get pulldown choice. */
  341.             if (currch < 97)            /* if user made a choice */
  342.               dosetup(currch);          /* execute option action. */
  343.           }  while (currch < 97);
  344.         wn_pdclose(&pdsetup);           /* NOW, close pulldown */
  345.         }
  346.         break;
  347.  
  348.       case 6:                           /* Modem -  single shot menu */
  349.         if (wn_pdopen(510,1,29,12,5,wa,ba,hka,&pdmodem, TRUE))
  350.         {
  351.           currch = wn_pdget(&pdmodem);  /* get pulldown choice. */
  352.           if (currch < 97)              /* if user made a choice */
  353.           {
  354.             wn_pdclose(&pdmodem);       /* close pulldown */
  355.             domodem(currch);            /* execute option action. */
  356.             return(0);
  357.           }
  358.         }
  359.         break;
  360.  
  361.       case 7:                           /* help - STICKY menu */
  362.         if (wn_pdopen(510,1,49,14,4,wa,ba,hka,&pdhelp, TRUE))
  363.         {
  364.           do
  365.           {
  366.             currch = wn_pdget(&pdhelp); /* get pulldown choice. */
  367.             if (currch < 97)            /* if user made a choice */
  368.               dohelp(currch);           /* execute option action. */
  369.           }  while (currch < 97);
  370.         wn_pdclose(&pdhelp);            /* NOW, close pulldown */
  371.         }
  372.         break;
  373.  
  374.       case 99:                          /* ESC from main menu - EXIT. */
  375.        return(0);
  376.        break;
  377.  
  378.       default:                          /* Can't really get here */
  379.        break;
  380.     }                                   /* end switch */
  381.  
  382. /* 
  383. ** If user escaped a pulldown menu by the left or right arrow use
  384. ** ForceChoice to change the barmenu and immediately activate its
  385. ** pulldown. At either end of menu, loop to the other end.
  386. ** If the option doesn't have a pulldown menu (typ == N), skip to
  387. ** the next one that does. 
  388. */
  389.  
  390.     if (currch == 97)                   /* left arrow was pressed */
  391.     {
  392.       wn_pdupdate(&mainbar, mainbar.lndx, PDNORMAL);  /* unmark old choice*/
  393.       do
  394.       {
  395.         mainbar.lndx = (--mainbar.lndx < mainbar.fm) ? mainbar.lm : mainbar.lndx;
  396.       } while (mainbar.scrn[mainbar.lndx].type == 'N');
  397.       ForceChoice = mainbar.lndx;
  398.     }
  399.     else if (currch == 98)              /* right arrow was pressed */
  400.     {
  401.       wn_pdupdate(&mainbar, mainbar.lndx, PDNORMAL);  /* unmark old choice */
  402.       do
  403.       {
  404.         mainbar.lndx = (++mainbar.lndx > mainbar.lm) ? mainbar.fm : mainbar.lndx;
  405.       } while (mainbar.scrn[mainbar.lndx].type == 'N');
  406.       ForceChoice = mainbar.lndx;
  407.     }
  408.     else                                /* ESC, so */
  409.       ForceChoice = -1;                 /* let user pick an option. */
  410.   }                                     /* end while. */
  411. }                                       /* END of DoMenu. */
  412.  
  413. /* ======================= [[ FILE MANAGER ]] ============================= */
  414.  
  415. void dofileman(ch)                      /* file manager */
  416. int ch;
  417. {
  418. WINDOWPTR wn;
  419. static char *msg = "File";
  420. int LoadType, SaveType, SaveAsType;
  421.  
  422.   switch (ch)
  423.   {
  424.     case 1:                             /* file load */
  425.     case 7:                             /* exit program */
  426.       LoadType = wn_pdtype(&pdfile, 1, 0, FALSE);  /* get current type */
  427.       SaveType = wn_pdtype(&pdfile, 2, 0, FALSE);
  428.       SaveAsType = wn_pdtype(&pdfile, 3, 0, FALSE);
  429.       if ((LoadType == 'S') && (SaveType == 'A') && (SaveAsType == 'A'))
  430.       {
  431.         wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  432.         wn_puts(wn, 0, 14, "Current Data Has Not Been Saved");
  433.         v_getch();
  434.         wn_clr(wn);
  435.         wn_puts(wn, 0, 8, "User Should Be Given The Option To Save It");
  436.         v_getch();
  437.         wn_close(wn);
  438.       }
  439.       if (ch == 7) break;               /* all done for program exit. */
  440.  
  441.       /* set types to indicate that data is loaded, but not yet saved. */
  442.       wn_pdtype(&pdfile, 1, 'S', TRUE);
  443.       wn_pdtype(&pdfile, 2, 'A', TRUE);
  444.       wn_pdtype(&pdfile, 3, 'A', TRUE);
  445.       wn_pdactive(&pdview, 1, TRUE);    /* activate View/Input option */
  446.       wn_pdactive(&mainbar, 4, TRUE);   /* activate the Run option */
  447.       wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  448.       wn_puts(wn, 0, 13, "User Would Load A Data File Here");
  449.       v_getch();
  450.       wn_clr(wn);
  451.       wn_puts(wn, 0, 6, "Data Loaded...Run And View/Input Are Now Active.");
  452.       v_getch();
  453.       wn_close(wn);
  454.       break;
  455.  
  456.     case 2:                             /* file save */
  457.     case 3:                             /* file save as */
  458.       LoadType = wn_pdtype(&pdfile, 1, 0, FALSE);  /* get current type */
  459.       if (LoadType == 'A')
  460.       {
  461.         wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  462.         wn_puts(wn, 0, 10, "There Is No Data To Save...Use File Load");
  463.         v_getch();
  464.         wn_close(wn);
  465.       }
  466.       else
  467.       {
  468.         if (ch == 2)                    /* set types to indicate that */
  469.           wn_pdtype(&pdfile, 2, 'S', TRUE);     /* data is saved */
  470.         else
  471.           wn_pdtype(&pdfile, 3, 'S', TRUE);
  472.         wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  473.         wn_puts(wn, 0, 13, "User Would Save A Data File Here");
  474.         v_getch();
  475.         wn_close(wn);
  476.       }
  477.       break;
  478.     case 5:                             /* print */
  479.       LoadType = wn_pdtype(&pdfile, 1, 0, FALSE);  /* get current type */
  480.       if (LoadType == 'A')
  481.       {
  482.         wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  483.         wn_puts(wn, 0, 10, "There Is No Data To Print...Use File Load");
  484.         v_getch();
  485.         wn_close(wn);
  486.         break;
  487.       }                  /* fall through to next case, if there is data */
  488.     case 4:                             /* change directory */
  489.     case 6:                             /* DOS Shell */
  490.       wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  491.       wn_printf(wn,"  %s choice: %d,  Press any key to continue...............",msg,ch);
  492.       v_getch();
  493.       wn_close(wn);
  494.       break;
  495.  
  496.     default:
  497.       break;
  498.   }
  499. }
  500.  
  501. /* ======================= [[ EDIT MANAGER ]] ============================= */
  502.  
  503. void doedit(ch)                         /* edit mngr */
  504. int ch;
  505. {
  506. WINDOWPTR wn;
  507.  
  508.   if (ch == 1)                          /* cut */
  509.   {
  510.     wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  511.     wn_puts(wn, 0, 18, "OK, You Cut, BUT I deal.");
  512.     v_getch();
  513.   }
  514.   else if (ch == 2)                     /* copy */
  515.   {
  516.     wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  517.     wn_puts(wn, 0, 10, "Copy Shareware Only!");
  518.     v_getch();
  519.   }
  520.   wn_close(wn);
  521. }
  522.  
  523. void doview(ch)                       /* view manager */
  524. int ch;
  525. {
  526.   WINDOWPTR wn;
  527.   static char *msg = "View";
  528.   int i, Choice;
  529.  
  530.   switch (ch)
  531.   {
  532.     case 1:                          /* view input */
  533.     case 2:                          /* view output */
  534.       wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  535.       wn_printf(wn,"  %s choice: %d,  Press any key to continue...............",msg,ch);
  536.       v_getch();
  537.       wn_close(wn);
  538.       break;
  539.  
  540.     case 3:                             /* view graphics */
  541.       /* display graph menu and get a choice */
  542.       if (wn_pdopen(510,5,16,12,4,wa,ba,hka,&pdgraph, TRUE))
  543.       {
  544.         do
  545.         {
  546.           Choice = wn_pdget(&pdgraph);  /* let user select item */
  547.             if (Choice < 97)            /* if he made a choice */
  548.               dographics(Choice);       /* next menu level */
  549.         } while (Choice < 97);
  550.         wn_pdclose(&pdgraph);           /*close this menu */
  551.       }
  552.       break;
  553.  
  554.     default:
  555.       break;
  556.   }                                     /* end switch */
  557. }
  558.  
  559. /* ======================= [[ GRAPHICS MANAGER ]] ========================= */
  560.  
  561. /*
  562. ** This routine demonstrates quite complex menu manipulation. User selects
  563. ** what he wants plotted on the X and Y axis of a graph. He can pick only
  564. ** one item for the X axis but several for the Y axis. PROBLEM. Several
  565. ** items appear on both menus. He must not be allowed to pick the same
  566. ** thing for both axis, so whatever he picks for the x axis is de-activated
  567. ** on the Y axis menu. Also, the 4th item on the View/Graphics menu - Display
  568. ** Graph should only be available if the user has selected items for BOTH
  569. ** the X and Y axis. ALSO, shows how to use the 'backdoor' approach to
  570. ** clearing toggles by directly accessing the menu structure. Bad
  571. ** programming, but sometimes necessary. 
  572. */
  573.  
  574. void dographics (Choice)
  575. int Choice;
  576. {
  577.   WINDOWPTR wn;
  578.   static char *msg = "Graphics";
  579.   int i,j;
  580.   int ch;
  581.  
  582.   switch (Choice)
  583.   {
  584.     case 1:                             /* x axis options */
  585.       if (wn_pdopen(510,7,20,14,5,wa,ba,hka,&pdxaxis, TRUE)) 
  586.          wn_pdget(&pdxaxis);            /* let user select x axis item */
  587.       wn_pdclose(&pdxaxis);
  588.  
  589. /*
  590. ** If BOTH X and Y options have been selected,
  591. ** activate the 4th Graphics option - Display Graph. 
  592. */
  593.  
  594.       if ((wn_pdgettog(&pdxaxis, -1) != -1) &&
  595.          (wn_pdgettog(&pdyaxis, -1) != -1))
  596.            wn_pdactive(&pdgraph, 4, TRUE);  /* activate */
  597.       else
  598.         wn_pdactive(&pdgraph, 4, FALSE);/* de-activate */
  599.       wn_pdopen(510,5,16,12,4,wa,ba,hka,&pdgraph, TRUE); /* re-display menu */
  600.       break;
  601.  
  602. /*
  603. ** Activate all y axis options and then de-activate what was
  604. ** picked for the x axis and turn its toggle OFF if its ON.
  605. ** NOTE: wn_pdactive and wn_pdgettog use option return codes, BUT
  606. ** wn_settog uses option indexes. 
  607. */
  608.  
  609.     case 2:                             /* y axis options, tricky */
  610.       for (i = pdyaxis.scrn[pdyaxis.fm].rv; i <= pdyaxis.scrn[pdyaxis.lm].rv; ++i)
  611.         wn_pdactive(&pdyaxis, i, TRUE); /* activate all options */
  612.  
  613.       i = wn_pdgettog(&pdxaxis, -1);    /* get return value of ON option*/
  614.       if (i != -1)                      /* an X axis option was ON. */
  615.       {
  616.         wn_pdactive(&pdyaxis, i, FALSE);/* de-activate it in Y axis */
  617.  
  618.         for (j = pdyaxis.fm; j <= pdyaxis.lm; ++j) /* find its option index */
  619.           if (pdyaxis.scrn[j].rv == i) break;     /* break when found */
  620.  
  621.         if (wn_pdgettog(&pdyaxis, i))   /* if toggle is On */
  622.           wn_pdsettog(&pdyaxis, j);     /* turn it OFF */
  623.       }
  624.  
  625.                                         /* now get the y axis options */
  626.       if (wn_pdopen(510,8,20,20,8,wa,ba,hka,&pdyaxis, TRUE))
  627.       {
  628.         do
  629.         {
  630.           ch = wn_pdget(&pdyaxis);      /* let user select y axis item */
  631.           if (ch == 7)                  /* clear all options */
  632.             /* directly access menu structure, YUK, but it works */
  633.             for (i = pdyaxis.fm; i <= pdyaxis.lm; ++i)
  634.               *(pdyaxis.scrn[i].t) = ' ';  /* blank 1st char */
  635.  
  636.             wn_pdopen(510,8,20,20,8,wa,ba,hka,&pdyaxis, TRUE); 
  637.         } while (ch < 97);
  638.       }
  639.       wn_pdclose(&pdyaxis);
  640.  
  641. /*
  642. ** If BOTH X and Y options have been selected,
  643. **  activate the 4th Graphics option - Display Graph. 
  644. */
  645.  
  646.       if ((wn_pdgettog(&pdxaxis, -1) != -1) &&
  647.          (wn_pdgettog(&pdyaxis, -1) != -1))
  648.            wn_pdactive(&pdgraph, 4, TRUE);  /* activate */
  649.       else
  650.         wn_pdactive(&pdgraph, 4, FALSE);    /* de-activate */
  651.       wn_pdopen(510,5,16,12,4,wa,ba,hka,&pdgraph, TRUE);
  652.       break;
  653.  
  654.     case 3:                             /* graph options */
  655.     case 4:                             /* draw graph */
  656.       wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  657.       wn_printf(wn,"  %s choice: %d,  Press any key to continue...............",msg,Choice);
  658.       v_getch();
  659.       wn_close(wn);
  660.       break;
  661.  
  662.     default:
  663.       break;
  664.   }  /* end switch */
  665. }
  666.  
  667. /*
  668. ** This routine is called by a MAIN menu choice that does not have a
  669. ** pulldown menu. ALSO, it demonstrates how selecting one menu option
  670. ** can activate another. In this case, View/Output is inactive until
  671. ** Run (which would process input and create output) is selected. 
  672. */
  673.  
  674. void dorun(void)                        /* run manager */
  675. {
  676. WINDOWPTR wn;
  677.  
  678.   wn=wn_open(0,15,10,60,2,NVIDEO,NVIDEO);
  679.   wn_puts(wn, 0, 7, "This Is A Main Menu Option With No Pulldown Menu");
  680.   wn_puts(wn, 1, 5, "Also, Selecting Run Activates The View/Output Options");
  681.   v_getch();
  682.   wn_close(wn);
  683.  
  684. /* 
  685. ** Activate the Run/Output and Graphics options 
  686. */
  687.  
  688.   wn_pdactive(&pdview, 2, TRUE);        /* 2 is the options return value, */
  689.   wn_pdactive(&pdview, 3, TRUE);        /* NOT its menu index number */
  690. }
  691.  
  692. /*
  693. ** This routine demonstrates how to handle a menu of toggles where only
  694. ** one at a time can be active (mutually exclusive). The code is very
  695. ** simple because wn_pdget handles everything and only returns when user
  696. ** presses ESC or if in a pulldown menu, the left/right arrow keys.
  697. ** ALSO, demonstrates the use of wn_pdgettog and wn_pdactive to activate
  698. ** a menu option based on a toggle status. 
  699. */
  700.  
  701. void dosetup(ch)                        /* setup */
  702. int ch;
  703. {
  704.   WINDOWPTR wn;
  705.   int IsActive;
  706.  
  707. /* 
  708. ** option 1 is a toggle (Color), so it never gets here. 
  709. */
  710.  
  711.                                         /* let user select a printer */
  712.   if (ch == 2)
  713.   {
  714.     if (wn_pdopen(510,4,27,8,8,wa,ba,hka,&pdprinters, TRUE))
  715.       wn_pdget(&pdprinters);            /* let user select a printer */
  716.     wn_pdclose(&pdprinters);
  717.  
  718. /* 
  719. ** Check if a printer is selected, if one is, we can print 
  720. */
  721.  
  722.     IsActive = wn_pdgettog(&pdprinters, -1); /* returns -1 of none are selected */
  723.     if (IsActive != -1)                 /* activate the File/Print option */
  724.       wn_pdactive(&pdfile, 5, TRUE);    /* set option with rv = 5 active */
  725.     else
  726.       wn_pdactive(&pdfile, 5, FALSE);   /* deactivate print option */
  727.  
  728. /* 
  729. ** This code just tells user what happened, normally it would not
  730. ** be present. 
  731. */
  732.  
  733.     wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  734.     if (IsActive != -1)
  735.       wn_puts(wn, 0, 4, "Printer Selected, So File/Print Option Is now Active");
  736.     else
  737.       wn_puts(wn, 0, 2, "No Printer Selected, So File/Print Option De-activated");
  738.     v_getch();
  739.     wn_close(wn);
  740.   }
  741.   else                                  /* plotters not available */
  742.   {
  743.     wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  744.     wn_puts(wn, 0, 10, "Plotter Support Available In Next Release");
  745.     v_getch();
  746.     wn_close(wn);
  747.   }
  748. }
  749.  
  750. /*
  751. ** Example of an alternate way to trap options that should not be
  752. ** selected at this time. Instead of de-activating them, leave them active
  753. ** but print an error message if they should not be selected. 
  754. */
  755.  
  756. void domodem(ch)                        /* modem manager */
  757. int ch;
  758. {
  759. WINDOWPTR wn;
  760.  
  761.   wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  762.   wn_puts(wn, 0, 8, "Sorry, You need a WIZZO Modem For This Action");
  763.   v_getch();
  764.   wn_close(wn);
  765. }
  766.  
  767. void dohelp(ch)                         /* help mngr */
  768. int ch;
  769. {
  770. WINDOWPTR wn;
  771. static char *msg = "Help";
  772.  
  773.   wn=wn_open(0,15,10,60,1,NVIDEO,NVIDEO);
  774.   wn_printf(wn,"  %s choice: %d,  Press any key to continue...............",msg,ch);
  775.   v_getch();
  776.   wn_close(wn);
  777. }
  778.  
  779. /* End */
  780.